package edu.nf.hotel.dao.impl;

import edu.nf.hotel.dao.CodeInterFace;
import edu.nf.hotel.entity.CodeEntity;
import edu.nf.hotel.util.ConnUtils;
import org.nf.db.util.SqlExecutor;
import org.nf.db.util.result.BeanHandler;

import java.sql.Timestamp;

/***
 * @Date(时间)2023-05-13
 * @Author 陈
 */


public class CodeDao implements CodeInterFace {
    SqlExecutor sqlExecutor = new SqlExecutor(ConnUtils.getConnection());
    @Override
    public int deleteCOde(Timestamp times) {
        return 0;
    }

    @Override
    public int updateCode(int id) {
        return 0;
    }

    @Override
    public int insertInto(CodeEntity entity) {
        String sql = "INSERT INTO email_info(Code_Name,Code_UserEmail)VALUES(?,?)";
        return sqlExecutor.executeUpdate(sql,entity.getCodeName(),entity.getCodeUserEmail());
    }

    @Override
    public int deleteCodes2(String email) {
       String sql  = "delete from Code_Email where Code_UserEmail = ?" ;

        return sqlExecutor.executeUpdate(sql,email);

    }

    @Override
    public CodeEntity query(String name) {
        String sql = "select Code_Id,Code_Name,Code_UserEmail,times from email_info where Code_Name=?";
        BeanHandler<CodeEntity> handler = new BeanHandler(CodeEntity.class);
        return sqlExecutor.executeQuery(sql,handler,name);
    }
}
